package com.cqjtu.eecs.controller;


import com.cqjtu.eecs.exception.NotFoundException;
import com.cqjtu.eecs.exception.ParamsErrorException;
import com.cqjtu.eecs.service.IAssessmentLinkService;
import com.cqjtu.eecs.utils.Assert;
import com.cqjtu.eecs.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * <p>
 * 考核-成绩 前端控制器
 * </p>
 *
 * @author    
 * @since 2022-03-07
 */
@RestController
@RequestMapping("/assess-score")
@Api(tags = "考核成绩接口")
public class AssessScoreController {

    @Autowired
    private IAssessmentLinkService assessmentLinkService;


    @GetMapping("/download/excel-template/{grade}/{majorName}/{courseName}")
    @ApiOperation(value = "课程成绩导入模板下载")
    public void downloadExcelTemplate(HttpServletResponse response, @PathVariable Integer grade,
                                      @PathVariable String majorName, @PathVariable String courseName) throws IOException {
        Assert.notBlank(majorName, new ParamsErrorException("专业名称不能为空"));
        Assert.notBlank(courseName, new ParamsErrorException("课程名称不能为空"));
        Assert.notNull(grade, new ParamsErrorException("年级不能为空"));
        List<List<String>> head = assessmentLinkService.getAssessmentLink(grade, majorName, courseName);
        ExcelUtil.writeExcelWithCustomHead(response, null, courseName + "成绩录入模板", head);
    }
}
